package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseReq;
import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.Brand;
import com.cskaoyan.bean.brand.bo.BrandCreateBo;
import com.cskaoyan.bean.brand.bo.BrandDeleteBo;
import com.cskaoyan.bean.brand.bo.BrandUpdateBo;
import com.cskaoyan.bean.brand.vo.BrandListVo;
import com.cskaoyan.bean.brand.vo.WXBrandDetailVo;
import com.cskaoyan.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author wangdezhao
 * @date 2021/6/5
 * @description
 */
@RestController
@RequestMapping("admin/brand")
public class AdminBrandController {

    @Autowired
    BrandService brandService;

    /**
     * 打印出所有商品品牌信息
     */
    @RequestMapping("list")
    public BaseRespVo list(BaseReq baseReq,String name,Integer id){
        BrandListVo brandListVo = brandService.getBrandList(baseReq, name, id);
        return BaseRespVo.ok(brandListVo);
    }

    /**
     * 添加商品品牌信息
     *
     */
    @RequestMapping("create")
    public BaseRespVo create(@RequestBody BrandCreateBo CreateBo){
        Integer effectedRows = brandService.createBrand(CreateBo);
        if(effectedRows == null || effectedRows != 1){
            return  BaseRespVo.fail("服务器正忙,添加失败,请稍后再试!");
        }
        return BaseRespVo.ok();
    }

    /**
     * 修改brand信息
     */
    @RequestMapping("update")
    public BaseRespVo update(@RequestBody BrandUpdateBo updateBo){
        Integer integer = brandService.updateBrand(updateBo);
        return BaseRespVo.ok(updateBo);
    }

    /**
     * 删除brand 信息  使用假删除
     */
    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody BrandDeleteBo deleteBo){
        brandService.deleteBrand(deleteBo);
        return BaseRespVo.ok();
    }

}
